<?php

class Exts_Security_SecureData {
	public $_data;
	protected $_vector = 'myvector';

	
	public static function Load ($data){
		$sd = new Exts_Security_SecureData();
		$sd->loadSecureData($data);
		return $sd;
	}

	public function __construct ($values = array()) {
		$this->_data = array();
		foreach ($values as $k => $v){
			$this->__set($k, $v);
		}
	}

	public function __set($name, $value){
		$this->_data[$name] = $value;
	}

	public function __get($name) {
		return $this->_data[$name];
	}

	public function getSecureData () {
		$encrypt = new Zend_Filter_Encrypt(
		array( 'adapter' => 'mcrypt', 'vector' => $this->_vector)
		);
		return base64_encode($encrypt->filter(serialize($this->_data)));
	}

	public function loadSecureData ($data) {
		$decrypt = new Zend_Filter_Decrypt(
		array( 'adapter' => 'mcrypt', 'vector' => $this->_vector)
		);
		$this->_data = unserialize($decrypt->filter(base64_decode($data)));
	}
}

